﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace For_FS_2013_1_User
{
    class Program
    {
        public const int defaultPort = 1;
        public static Users users;
        public static RemoteControl rc;
        public static bool authorizedAdmin;
        public static FileManager fm;
        public static DefaultConnector defCon;

        public static Connector con; //testing

        static void Main(string[] args)
        {
            authorizedAdmin = false;
            users = new Users();
            rc = new RemoteControl();
            fm = new FileManager();
            defCon = new DefaultConnector();

            con = new Connector(); // testing
            
            while (true)
            {
                string command = Console.ReadLine();
                if (command == "status")
                    Console.WriteLine(rc.Status());
                if (command == "cls" || command == "clear")
                    Console.Clear();
                if (command == "exit")
                {
                    if (authorizedAdmin)
                    {
                        rc.Send("disconnection");
                        users.LogoutUser(rc.GetAdmin());
                        authorizedAdmin = false;
                        rc.Disconnect();
                        Console.WriteLine("Administrator disconnected");
                    }
                    break;
                }
            }
            Console.WriteLine("Disconnection from the data base. . .");
            users.CloseConnection();
            Environment.Exit(1);
        }
    }
}
